#!/bin/sh
BKP_DIR=/wai2008/wbls4WAI/backup
BKP_IEEE80211_DIR=$BKP_DIR/iee80211
IEEE80211_DIR=/lib/modules/2.6.24-16-generic/kernel/net/ieee80211
IWL3945_DIR=/lib/modules/2.6.24-16-generic/ubuntu/wireless/iwlwifi/iwlwifi/compatible

if [ -z $1 ]; then
   echo ""
   echo "parâmetros válidos: driver|tools"
   echo ""
   exit
elif [ $1 = "driver" ]; then
	echo
	echo 'Restore Default Wireless Drivers'
	echo

	modprobe -r iwl3945
	sleep 2
	modprobe -r mac80211
	sleep 1
	echo 'upload backup driver ...'
	rm $IWL3945_DIR/iwl3945.ko
	cp $BKP_DIR/iwl3945.ko $IWL3945_DIR
	rm $IEEE80211_DIR/ieee80211.ko
	rm $IEEE80211_DIR/ieee80211_crypt.ko
	rm $IEEE80211_DIR/ieee80211_crypt_ccmp.ko
	rm $IEEE80211_DIR/ieee80211_crypt_tkip.ko
	rm $IEEE80211_DIR/ieee80211_crypt_wep.ko
	cp $BKP_IEEE80211_DIR/ieee80211.ko $IEEE80211_DIR
	cp $BKP_IEEE80211_DIR/ieee80211_crypt.ko $IEEE80211_DIR
	cp $BKP_IEEE80211_DIR/ieee80211_crypt_ccmp.ko $IEEE80211_DIR
	cp $BKP_IEEE80211_DIR/ieee80211_crypt_tkip.ko $IEEE80211_DIR
	cp $BKP_IEEE80211_DIR/ieee80211_crypt_wep.ko $IEEE80211_DIR
	echo '... upload backup finished'

	sleep 1
	modprobe mac80211
	sleep 2
	modprobe iwl3945

elif [ $1 = "tools" ]; then
	echo
	echo 'Restore Default Wireless Tools'
	echo

	echo 'upload backup tools ...'
	rm /lib/libiw.so.29
	cp $BKP_DIR/libiw.so.29 /lib/
	rm /sbin/iwlist
	cp $BKP_DIR/iwlist /sbin/
	echo '... upload backup finished'

else
   echo "parâmetros inválidos"
fi

echo
echo 'Restore finished'
echo
